package receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.example.menhoo.toollibrary.common.assist.Network;
import com.lidroid.xutils.util.LogUtils;

import application.UIApplication;

/**
 * 网络状态监听广播
 * @author yanglei
 *
 */
public class NetStateReceiver extends BroadcastReceiver{

	public static final String Action = UIApplication.PackageName+".Receiver.NetStateReceiver";
	@Override
	public void onReceive(Context context, Intent intent) {
		if (Action.equals(intent.getAction())){

			boolean isNetworkAvailable=false;
			String message = null;
			boolean isWifi =Network.isWifi(context);

			try{
				isNetworkAvailable = intent.getBooleanExtra("isNetworkAvailable",false);
				message = intent.getStringExtra("message");

				run(context,intent,isWifi,isNetworkAvailable,message==null?null:message);
			}
			catch (Exception e){
				LogUtils.e("NetStateReceiver error:"+e.getMessage());
			}

		}
		 
	}
	
	/**
	 * 重写此方法以便，执行自己的逻辑
	 * @param context
	 * @param intent
	 * @param isWifi 是否是wifi连接 true wifi; false gprs
	 * @param isNetworkAvailable 是否有网络  false 是没有
	 */
	public void run(Context context, Intent intent,boolean isWifi,boolean isNetworkAvailable,String message){

	}

}
